package com.creditease.shield.flow;

import java.net.InetSocketAddress;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.creditease.shield.flow.client.NettyClient;
import com.creditease.shield.flow.common.msg.Request;
import com.creditease.shield.flow.common.msg.Response;

/**
 * Created by xiaoleizhao on 2017/9/19.
 */
public class ClientApplication {
	static final int PORT = Integer.parseInt(System.getProperty("port", "8007"));
	private static final Logger log = LoggerFactory.getLogger(ClientApplication.class);

	public static void main(String[] args) throws Exception {

		//connect
        NettyClient newClient = new NettyClient();
        //TODO get from service registry
        String host = "127.0.0.1";
        int port = 8007;
        newClient.connect(new InetSocketAddress(host,port));
       try{ 
	    	   for(int i=0;i<10;i++){
	        	Request request=new Request();
	            request.setTraceId(Long.toString(System.currentTimeMillis()));
	            request.setKeyName("TEST-KEY");
	            Response response=newClient.syncSend(request);
	            System.out.println(response.getFlowNo());
	            //Thread.sleep(1000);
	    	   }
    	   }catch(Exception e){
            	log.error(e.getMessage());
            	newClient.close();
            }
//       finally{
//            	if(newClient!=null){
//            		newClient.close();
//            	}
//            }
           
        
	}

}